﻿using System;
using System.Collections.Generic;
using System.Web;
using AspNetCs.Model;
using AspNetCs.Enumerations.Channel_Enum;
using AspNetCs.Common;

/// <summary>
///管理员后台常用基类
/// </summary>
public class Admin_BasePage : BasePage
{
    /// <summary>
    /// 管理员Session变量值
    /// </summary>
    protected string Admin_SessionStr = "AdminInfo";
    protected string Agent_SessionStr = "AgentInfo";

    public Admin_BasePage()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }


    /// <summary>
    /// 检查用户Session是否过期
    /// </summary>
    public void IsExit()
    {
        if (Session[Admin_SessionStr] != null)
        {
            Admin_Model model = (Admin_Model)Session["AdminInfo"];
            IsExit(model);
        }
        else
        {

            HttpContext.Current.Response.Redirect(configInfo.InstallDir + configInfo.AdminDir + "/Admin_Login.Aspx");
            HttpContext.Current.Response.End();
        }
    }
    /// <summary>
    /// 检查用户Session是否过期 
    /// </summary>
    /// <param name="model"></param>
    public void IsExit(Admin_Model model)
    {
        if (model != null)
        {
            if (model.Id <= 0)
            {
                HttpContext.Current.Response.Redirect(configInfo.InstallDir + configInfo.AdminDir + "/Admin_Login.Aspx");
                HttpContext.Current.Response.End();

            }
        }
        else
        {
            HttpContext.Current.Response.Redirect(configInfo.InstallDir + configInfo.AdminDir + "/Admin_Login.Aspx");
            HttpContext.Current.Response.End();
        }

    }
    /// <summary>
    /// 检查用户Session是否过期
    /// </summary>
    public void IsExit(string url)
    {
        if (Session[Admin_SessionStr] != null)
        {
            Admin_Model AdminModel = (Admin_Model)Session["AdminInfo"];
            IsExit(AdminModel);
        }
        else
        {

            HttpContext.Current.Response.Redirect(url);
            HttpContext.Current.Response.End();
        }
    }

    /// <summary>
    /// 检查代理商Session是否过期(代理商)
    /// </summary>
    public void IsExitAgent(string url)
    {
        if (Session[Agent_SessionStr] != null)
        {
            AgentModel model = (AgentModel)Session[Agent_SessionStr];
            IsExitAgent(model);
        }
        else
        {

            HttpContext.Current.Response.Redirect(url);
            HttpContext.Current.Response.End();
        }
    }

    /// <summary>
    /// 检查代理商Session是否过期(代理商)
    /// </summary>
    public void IsExitAgent()
    {
        if (Session[Agent_SessionStr] != null)
        {
            AgentModel model = (AgentModel)Session[Agent_SessionStr];
            IsExitAgent(model);
        }
        else
        {

            HttpContext.Current.Response.Redirect("Agent_Login.aspx");
            HttpContext.Current.Response.End();
        }
    }
    /// <summary>
    /// 检查代理商Session是否过期(代理商) 
    /// </summary>
    /// <param name="model"></param>
    public void IsExitAgent(AgentModel model)
    {
        if (model != null)
        {
            if (model.Id <= 0)
            {
                HttpContext.Current.Response.Redirect("Agent_Login.aspx");
                HttpContext.Current.Response.End();

            }
        }
        else
        {
            HttpContext.Current.Response.Redirect("Agent_Login.aspx");
            HttpContext.Current.Response.End();
        }

    }

    /// <summary>
    /// 代理商退出
    /// </summary>
    protected void Agent_LoginOut()
    {
        Session[Agent_SessionStr] = null;
        Response.Write("<script>parent.location.href='Agent_login.Aspx';</script>");
        Response.End();
    }

    /// <summary>
    /// 代理商资料
    /// </summary>
    protected AgentModel AgentInfo
    {
        get
        {
            return (AgentModel)Session[Agent_SessionStr];
        }
    }
    protected string AgentPurView
    {
        get
        {
            string Result = AgentInfo.Purview;
            return Result;
        }

    }




    /// <summary>
    /// 管理员资料
    /// </summary>
    protected Admin_Model AdminInfo
    {
        get
        {
            return (Admin_Model)Session[Admin_SessionStr];
        }
    }
    protected string AdminPurView
    {
        get
        {
            string Result = "";
            if (AdminInfo.Purview == 1)
            {
                Result = "超级管理员";
            }
            else
            {
                Result = "普通管理员";
            }
            return Result;
        }

    }
    /// <summary>
    /// 管理员退出
    /// </summary>
    protected void Admin_LoginOut()
    {
        Session[Admin_SessionStr] = null;
        Response.Write("<script>parent.location.href='" + configInfo.InstallDir + configInfo.AdminDir + "/Admin_login.Aspx';</script>");
        Response.End();
    }

    /// <summary>
    /// 管理员上传图片的文件路径
    /// </summary>
    protected string Admin_UpFolder
    {
        get
        {
            return configInfo.UpFolder + "master_up";
        }
    }

    /// <summary>
    /// 模板路径
    /// </summary>
    /// <returns></returns>
    protected string Admin_SkinFolder(Channel_Type channel)
    {
        return StringHelper.ReadConfig("TempleSkin") + channel.ToString();
    }

}
